
//接口   约束对象类型
interface MYPROPS {
    //  | 联合
    [index: string | number]: string | number;
    // name:string;
    // age:string;
}
let obj: MYPROPS = {
    name: '胡子瑜',
    0: 12,
}
console.log(obj);



interface ARRAYTP {
    [index: number]: string | number
}

let arr: ARRAYTP = ['2001B', '2001c']

console.log(arr);



//泛型  <T> T代表任意 也可以理解传入什么类型就是什么类型
//可以把类型约束理解为传值设置变量时候的校验 设置属性可选就相当于取消这个变量的必填校验 
interface MYOBJS {
    name: string
    age?: number  // ?可选
}

let obj1: Array<MYOBJS> = [{ name: "123", age: 123 }]


// readonly设置成只读属性
interface MOPR {
    readonly name: string;
    age?: number
}

let obj2: MOPR = {
    name: '1110',
    age: 12
}
obj2.name = 'wwww'
console.log(obj2);


//继承
interface MYOBJ {
    age: number;
    class: string;
}

interface MYOBJ1 extends MYOBJ  {
    name: string
}
let obj3: MYOBJ1 = {
    name: '123',
    age: 18,
    class: '12x'
}




//函数
function myFun(name:string,...resetName:(string|number)[]){
    console.log(name,'name');
    console.log(resetName,'resetName');
    
    
}
console.log(myFun('胡子瑜'));



interface myobj{
    name:string,
    age:number
}

// 函数参数设置可选 只能给最后一个形参添加 否则会报错
function myFun11(first:string,secend:number,toipis?:boolean){
    return true
}
console.log(myFun11('2',11,true));



function allFun(str:string,num:number):any{
    return str+num
}

class Greeter{
    greeting1:string;
    name1:string;
    constructor(message:string,name:string){
        this.greeting1=message
        this.name1 = name
    }

    greet(){
        return "hai" + this.greeting1;
    }
    setName(){
        this.name1='拉拉'
        return this.name1
    }
}
let greeter = new Greeter('world','战开始');
console.log(greeter.setName(),'1234q');
console.log(greeter,'greeter');



class Greeter1{
    name:string;
    constructor(name:string){
      this.name = name  
    }
    greet(){
        return "hello"+this.name
    }
}
class Person extends Greeter1{
    list:string;
    constructor(name:string){
        super(name)
        this.list=name
    }
    getlist(){
        return this.list
    }
}

let greeter = new Greeter1('world')
let newPer = new Person('666')
console.log(newPer.greet(),'newPerson');
